package com.huitong.common.satoken.config;

import cn.dev33.satoken.dao.SaTokenDao;
import cn.dev33.satoken.jwt.StpLogicJwtForSimple;
import cn.dev33.satoken.stp.StpInterface;
import cn.dev33.satoken.stp.StpLogic;
import com.huitong.common.core.factory.YmlPropertySourceFactory;
import com.huitong.common.satoken.dao.SaTokenDaoImpl;
import com.huitong.common.satoken.service.StpInterfaceImpl;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.PropertySource;

/**
 * Sa-Token配置
 *
 * @author fromdrowning
 * @date 2024/3/17 8:27
 */
@AutoConfiguration
@PropertySource(value = "classpath:common-satoken.yml", factory = YmlPropertySourceFactory.class)
public class SaTokenConfiguration {

    /**
     * 配置会话传递逻辑
     *
     * @return 会话传递逻辑
     */
    @Bean
    public StpLogic stpLogicCustomizer() {
        return new StpLogicJwtForSimple();
    }

    /**
     * 配置权限管理
     *
     * @return 权限管理
     */
    @Bean
    public StpInterface stpInterfaceCustomizer() {
        return new StpInterfaceImpl();
    }

    /**
     * 配置Sa-Token持久层
     *
     * @return 持久层
     */
    @Bean
    public SaTokenDao saTokenDaoCustomizer() {
        return new SaTokenDaoImpl();
    }
}
